package com.lovo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lovo.model.ServiceOrder;
import com.lovo.service.ServiceOrderService;
import com.lovo.util.SqlSessionUtil;
import com.lovo.VO.ServiceOrderVo;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ServiceOrderServerImpl implements ServiceOrderService {
    SqlSession sqlSession= SqlSessionUtil.getSqlSession();
    @Override
    public int deleteByPrimaryKey(Integer serviceOrderId) {
        String stmt = "com.lovo.dao.ServiceOrderMapper.deleteByPrimaryKey";
        int n=sqlSession.update(stmt,serviceOrderId);
        sqlSession.commit();
        return n;
    }

    @Override
    public int insert(ServiceOrder record) {
        return 0;
    }

    @Override
    public int insertSelective(ServiceOrder record) {
        return 0;
    }

    @Override
    public ServiceOrder selectByPrimaryKey(Integer serviceOrderId) {
        String stmt="com.lovo.dao.ServiceOrderMapper.selectByPrimaryKey";
        ServiceOrder ov=sqlSession.selectOne(stmt,serviceOrderId);
        sqlSession.commit();
        return ov;
    }
    @Override
    public int updateByPrimaryKey(ServiceOrder vo) {
        String stmt="com.lovo.dao.ServiceOrderMapper.updateByPrimaryKeySelective";
        int n=sqlSession.update(stmt,vo);
        sqlSession.commit();
        return n;
    }

    @Override
    public PageInfo<ServiceOrderVo> selectAll(ServiceOrderVo vo,int pageNo,int pageSize) {
        String stmt="com.lovo.dao.ServiceOrderMapper.selectAll";
        //注意：这句话一定要放在读取数据的前面，才能实现拦截
        PageHelper.startPage(pageNo,pageSize);
        List<ServiceOrderVo> commodityOrderVo=sqlSession.selectList(stmt,vo);
        //将集合对象放入到PageInfo中
        PageInfo<ServiceOrderVo> page = new PageInfo<ServiceOrderVo>(commodityOrderVo);
        sqlSession.commit();
        return page;
    }
}
